Skip to content

Add regex assertions assert_all_strings_contain() and assert_string_contains()#143

Merged
selkamand merged 2 commits intomainfrom
codex/add-assert_matches_regex-function
Feb 8, 2026
Merged

Add regex assertions assert_all_strings_contain() and assert_string_contains()#143
selkamand merged 2 commits intomainfrom
codex/add-assert_matches_regex-function

Conversation

@selkamand
Copy link
Owner

Motivation

  • Replace the old regex assertion with clearer, focused APIs for string regex checks and centralize pattern validation in a helper.
  • Provide both a vector-level assertion (assert_all_strings_contain) and a string-level assertion (assert_string_contains) that reuse the same validation logic.

Description

  • Add contains_pattern() helper that validates pattern and grepl flags and returns whether all elements match the regex.
  • Implement assert_all_strings_contain() as a chain of assert_character_vector, assert_no_missing, and an assert_create() wrapper around contains_pattern with a default error message.
  • Implement assert_string_contains() as assert_create_chain(assert_string, assert_all_strings_contain) so single-string checks reuse the vector-level logic.
  • Remove the old assert_matches_regex manpage and update NEWS.md, NAMESPACE, and tests to reflect the new assertion names and behavior.

Testing

  • Ran devtools::document() which regenerated Rd files and updated NAMESPACE successfully.
  • Ran devtools::test() and unit tests passed after adding coverage for assert_string_contains (tests report all tests passing).
  • Ran devtools::check() which completed but returned 1 WARNING (missing qpdf for PDF size checks) and 1 NOTE (unable to verify current time), causing a non-zero exit status; there are no test failures reported.

Codex Task

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c64c50e058

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +12 to +14
contains_pattern <- function(x, pattern, ignore.case = FALSE, perl = FALSE, fixed = FALSE, useBytes = FALSE) {
if (!is_string(pattern))
return("'pattern' must be a string (length 1 character vector)")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject missing regex patterns before grepl

When pattern is NA_character_, is_string(pattern) returns TRUE, so this helper proceeds to grepl() and R throws invalid 'pattern' argument instead of the assertion’s normal error formatting. That means callers who pass a missing pattern (e.g., pattern = NA) get a base error rather than the expected assertion message. Consider explicitly rejecting is.na(pattern) (or reusing assert_no_missing for pattern) so missing patterns fail with a consistent assertion error.

Useful? React with 👍 / 👎.

@selkamand selkamand linked an issue Feb 8, 2026 that may be closed by this pull request
@selkamand selkamand merged commit 64f61dd into main Feb 8, 2026
7 checks passed
@selkamand selkamand deleted the codex/add-assert_matches_regex-function branch February 8, 2026 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add string regex assertions

1 participant